﻿using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Easy.Common;

namespace Easy.DAL
{
    public class EntityLinkDAL
    {
        private readonly SqlDatabase sqldb = new SqlDatabase(Config.TulingBuyCrmConnectString);
        public void saveEntityLink_toSql(Guid EntityLinkId, string EntityLinkName, string Entity, Guid Role, Guid ParentId, string src, string order)
        {
            sqldb.ExecuteDataSet("sp_Form_SaveEntityLink", new object[]{
                EntityLinkId,
                EntityLinkName,
                Entity,
                Role,
                ParentId,
                src,
                order
            });
        }
        public DataSet getEntityLink_fromSqlByRole(string Entity, Guid Role)
        {
            return sqldb.ExecuteDataSet("sp_Form_GetEntityLink", new object[]{
                Entity,
                Role
            });
        }
        public DataSet getEntityLink_fromSqlByUser(string Entity, Guid systemuserid)
        {
            return sqldb.ExecuteDataSet("sp_Form_GetEntityLinkByUser", new object[]{
                Entity,
                systemuserid
            });
        }
        public void cleanEntityLink(string Entity, Guid Role)
        {
            sqldb.ExecuteNonQuery("sp_Form_DeleteEntityLink", new object[] { Entity, Role });
        }

        //N2N操作
        public DataSet OpeateN2N_toSql(string ids, string entityM, string entityB, string entityA, string linkentityid, string type)
        {
            return sqldb.ExecuteDataSet("sp_OpeateN2NItem", new object[]{
                ids,
                entityM,
                entityB,
                entityA,
                linkentityid,
                type
            });
        }
    }
}
